﻿using System;
using System.Windows.Forms;

namespace QAToolsAddin.GenericDialogs.Fields {

    public class FieldDateTime : Field, IField {
        readonly DateTimePicker _control;

        public FieldDateTime(string name, string info, DateTime value, string format = null, DateTime? min = null, DateTime? max = null, bool retore = false)
            : base(name, info, retore) {
            _control = new DateTimePicker {
                Value = value,
                ShowUpDown = false
            };
            if (min != null)
                _control.MinDate = (DateTime)min;
            if (max != null)
                _control.MaxDate = (DateTime)max;
            if (string.IsNullOrEmpty(format) == false) {
                _control.Format = DateTimePickerFormat.Custom;
                _control.CustomFormat = format;
            }
        }

        public override Control Control {
            get { return _control; }
        }

        public DateTime Value {
            get { return _control.Value; }
            set { _control.Value = value; }
        }

        object IField.Value {
            get { return Value; }
            set { Value = (DateTime)value; }
        }

    }

}
